package his.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import his.entity.FmedItem;
import his.persistence.FmedItemMapper;
import his.service.FmedItemService;
import org.example.his.common.api.CommonResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FmedItemServiceImpl implements FmedItemService {

    @Autowired
    FmedItemMapper fmedItemMapper;

    @Override
    public CommonResponse delete_item(String item_code) {


        return null;
    }

    @Override
    public CommonResponse<List<FmedItem>> search_item(String keywords) {

        QueryWrapper<FmedItem> queryWrapper1=new QueryWrapper<>();
        queryWrapper1.eq("ItemCode",keywords);
        List<FmedItem> fmedItemList=fmedItemMapper.selectList(queryWrapper1);
        if(fmedItemList.size()>0){
            return CommonResponse.createForSuccess(fmedItemList);
        }else{
            QueryWrapper<FmedItem> queryWrapper2=new QueryWrapper<>();
            queryWrapper2.eq("ItemName",keywords);
            List<FmedItem> fmedItemList1=fmedItemMapper.selectList(queryWrapper2);
            if(fmedItemList1.size()>0){
                return CommonResponse.createForSuccess(fmedItemList1);
            }else{
                return CommonResponse.createForError("搜索失败");
            }
        }

    }

    @Override
    public CommonResponse<List<FmedItem>> getall_item() {
        QueryWrapper<FmedItem> queryWrapper1=new QueryWrapper<>();
        List<FmedItem> fmedItemList=fmedItemMapper.selectList(queryWrapper1);
        if(fmedItemList.size()>0){
            return CommonResponse.createForSuccess(fmedItemList);
        }else{
            return CommonResponse.createForError("查询失败");
        }

    }
}
